//执行act ,如收藏\点赞等记录行为,必须会员
//实例: <a href="javascript:" onclick="act(this, '/app/laoha/post/act?root=post&id=11','good')" class="act-good"><span>1</span>人点赞</a> 
//有记录时,类名 act-{type}-ed,无记录时类名act-{type}
function act(obj,url,act)
{
    var del = $(obj).hasClass('act-'+act+'-ed') ? 1 : 0;
    var url = del ? url+'&del=1' : url;
    $.ajax({
        url: url,
        type: 'post',
        data: {act:act},
        success: function (e) {
            if (e.code != 0) {
                alert(e.msg);
                return;
            }
            $(obj).removeClass('act-'+act+'-ed').removeClass('act-'+act).addClass(del ? 'act-'+act : 'act-'+act+'-ed');
            if (del) {
                $(obj).children('.act').addClass("d-none");
                $(obj).children('.acted').removeClass("d-none");
            } else {
				$(obj).children('.act').removeClass("d-none");
                $(obj).children('.acted').addClass("d-none");
            }
        }
    });
}

//自增,游客也可操作
//例 <a href="javascript:" onclick="add(this, '/app/laoha/post/add?field=goods&id=<?=$data['id']?>')" class="link-underline-light add-goods"><i class="far fa-heart"></i> <span><?=$data['goods']?></span> 点赞</a>
function add(obj,url)
{
    var url = url;
    $.ajax({
        url: url,
        success: function (e) {
            if (e.code != 0) {
                alert(e.msg);
                return;
            }
			$(obj).children('span').html((parseInt($(obj).children('span').html()) + 1));	
			$(obj).removeAttr('onclick');			
			alert('操作成功!');
        }
    });
}


//例 <a href="javascript:;" onclick="check('/app/laoha/admin/post/check?status=1&id=<?=$data['id']?>','reload')">审核</a>
function check(url,obj)
{
    var url = url;
    $.ajax({
        url: url,
        success: function (e) {
            if (e.code != 0) {
                alert(e.msg);
                return;
            }
            alert('操作成功!');
			$('#'+obj).remove();			
			
        }
    });
}

function logout(url)
{
    var url = url;
    $.ajax({
        url: url,
        success: function (e) {
            if (e.code != 0) {
                alert(e.msg);
                return;
            }
            //alert(e.msg);
			location.reload();
        }
    });
}